package leetcode.editor.cn.q1xx

import leetcode.editor.cn.TreeNode

class Q101 {

    fun isSymmetric(root: TreeNode?): Boolean {
        if (root == null) {
            return true
        }

        return isSymmetric(root.left, root.right)
    }

    private fun isSymmetric(l: TreeNode?, r: TreeNode?): Boolean {
        return if (l == null && r == null) {
            true
        } else if (l == null || r == null) {
            false
        } else {
            (l.`val`==r.`val`) && isSymmetric(l.left, r.right) && isSymmetric(l.right, r.left)
        }
    }
}